package isssr.bean.entity;

import java.io.Serializable;
import java.lang.reflect.Field;

import javax.faces.bean.ManagedBean;
import javax.persistence.Entity;

import isssr.bean.utility.HibernateUtility;

@ManagedBean
@Entity
public class Role extends MetaEntity{


	private String title;
	private String description;
	private Integer Level;
	private Boolean goalOwnerPermission;
	
	protected Serializable getMetaID()
	{
		return this.title;
	}

	public Role()
	{
		
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getLevel() {
		return Level;
	}

	public void setLevel(Integer level) {
		Level = level;
	}

	public Boolean getGoalOwnerPermission() {
		return goalOwnerPermission;
	}

	public void setGoalOwnerPermission(Boolean goalOwnerPermission) {
		this.goalOwnerPermission = goalOwnerPermission;
	}	
	
	public boolean equals(Object o)
	{
		if(o==null)
			return false;
		
		if(this == o) 
			return true;
		
		if(this.getClass() != o.getClass())
			return false;
		
		Role otherRole = (Role) o;
		Object thisValue;
		Object otherValue;
		
		try
		{
			for(Field f : this.getClass().getDeclaredFields())
			{
				thisValue = f.get(this);
				otherValue = f.get(otherRole);
				
				if(thisValue==null)
				{
					if(otherValue!=null)
						return false;
				}
				else if(!thisValue.equals(otherValue))
				{
					return false;
				}
			}
		}
		catch(IllegalArgumentException ex)
		{
			ex.printStackTrace();
			return false;
		}
		catch(IllegalAccessException ex)
		{
			ex.printStackTrace();
			return false;
		}
		
		return true;
	}
}
